#include "DialogFontAnimated.hpp"

DialogFontAnimated::DialogFontAnimated(int charHeight, int charWidth, int totalChars, int columns, int letterSpacing)
{
    if(!m_img.loadFromFile("Ressources/Fonts/pixelFont.png"))
    {
        std::cout<<"Img Load Error";
        exit(0);
    }
    m_charHeight = charHeight;
    m_charWidth = charWidth;
    m_totalChars = totalChars;
    m_columns = columns;
    m_letterSpacing = letterSpacing;

}

DialogFontAnimated::~DialogFontAnimated()
{

}

void DialogFontAnimated::printChar(char letter,int x, int y, sf::Image *image)
{

    int frame;
    int line = 0;
    //printf("Bitmap character: %c -- %d\n",letter,letter);
    if(letter > 32 && letter < 48)
    {
        frame =(letter-23);
        line = 2;
        m_charWidth = 12;
        m_charHeight = 22;
    }
    //Meta char part2
    //58 - 64
    if(letter > 62 && letter < 65)
    {
        frame = (letter - 38);
        line = 2;
        m_charWidth = 12;
        m_charHeight = 22;
    }
    //1-9
    //48 - 57
    if(letter > 47 && letter < 58)
    {
        frame=(letter - 48);
        line = 2;
        m_charWidth = 12;
        m_charHeight = 22;
    }
    //a-z
    //97 - 122
    if(letter > 96 && letter < 123)
    {
        frame= (letter - 97);
        line = 1;
        m_charWidth = 12;
        m_charHeight = 22;
    }
    //A-Z
    //65 - 90
    if(letter >64 && letter < 91)
    {
        frame= letter - 65;
        line = 0;
        m_charWidth = 12;
        m_charHeight = 22;
    }

    int u = (frame % m_columns) * m_charWidth;
    int v = line* m_charHeight;
    //std::cout <<"u,v-------frame : "<<u<<","<<v<<"------"<<frame<<"\n";
    image->copy(m_img, x, y, sf::IntRect(u,v,m_charWidth, m_charHeight), false);
}

int DialogFontAnimated::getCharHeight()
{
    return m_charHeight;
}

int DialogFontAnimated::getCharWidth()
{
    return m_charWidth;
}

int DialogFontAnimated::getLetterSpacing()
{
    return m_letterSpacing;
}
